package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.IPermissionService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by abb on 2018-07-09.
 */
@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    //定位权限页面
    @RequestMapping("")
    public String index(){
        return "permission";
    }

    //加载数据列表
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){
        return permissionService.query(qo);
    }
    //加载所有权限数据列表
    @RequestMapping("listAll")
    @ResponseBody
    public PageResult listAll(){
        return permissionService.listAll();
    }
    //查询权限根据角色的ID
    @RequestMapping("queryByRoleId")
    @ResponseBody
    public PageResult queryByRoleId(Long roleId){
        return permissionService.queryByRoleId(roleId);
    }

    //重新加载权限
    @RequestMapping("reload")
    @ResponseBody
    public JsonResult reload(){
        JsonResult jsonResult = new JsonResult();

        try {
            permissionService.reload();
        }catch (Exception e){
            e.printStackTrace();

            jsonResult.setMsg("get wrong");
        }
        return jsonResult;
    }

}
